﻿#region Includes
using System;
using System.Drawing;
using System.Collections.Generic;

using OpenTK;
using OpenTK.Graphics;
#endregion

namespace GingerGL.Graphics
{
    //------------------------------------------------------------//
    /// <summary>
    /// Common Material Class
    /// </summary>
    [Serializable]
    public class Material
    {
        //--------------------------------------------------------//
        #region Variables
        static public readonly Material Empty = new Material(String.Empty);
        static public readonly Material Default = new Material("Default");
        static public MaterialManager Manger = new MaterialManager();

        public string Name { get; set; }
        public Color4 Color { get; set; }
        public Color4 Ambient { get; set; }
        public Color4 Specular { get; set; }
        public Color4 Emmision { get; set; }
        public Color4 Diffuse { get; set; }
        public float Shine { get; set; }
        public Texture Texture { get; set; }
        #endregion
        //--------------------------------------------------------//
        #region Constructors
        /// <summary>
        /// Initializes anew instance of object
        /// </summary>
        public Material() : this(String.Empty) { }
        /// <summary>
        /// Initializes anew instance of object
        /// </summary>
        /// <param name="name">Name of Material</param>
        public Material(string name)
        {
            Name = name;
            Texture = null;
            Color = Color4.White;
            Ambient = Color4.Black;
            Specular = Color4.Transparent;
            Emmision = Color4.Transparent;
            Diffuse = Color4.Transparent;
            Shine = 0.0f;
        }
        /// <summary>
        /// Initializes anew instance of object
        /// </summary>
        /// <param name="name">New Texture</param>
        public Material(Image img) : this(img, false) { }
        /// <summary>
        /// Initializes anew instance of object
        /// </summary>
        /// <param name="name">New Texture</param>
        public Material(Image img, bool clamp) : this(String.Format("Image: {0}", img.GetHashCode()))
        {
            Texture = Texture.Instance.FromImage(img, clamp);                     //add new texture
        }
        /// <summary>
        /// Initializes anew instance of object
        /// </summary>
        /// <param name="name">Color</param>
        public Material(Color4 color) : this("Default") 
        { 
            Color = color;                                      //just set color
        }
        /// <summary>
        /// Initializes anew instance of object
        /// </summary>
        /// <param name="name">Color</param>
        public Material(Color color) : this("Default")
        {
            Color = 
                new Color4(color.R, color.G, color.B, color.A); //just set color
        }
        #endregion
        //--------------------------------------------------------//
        #region Methods
        /// <summary>
        /// Invalidate datda
        /// </summary>
        public void Invalidate()
        {
            if (Texture != null)                                //any textures?
                Texture.Invalidate();                           //and invalidate them
        }
        /// <summary>
        /// Executes Materials
        /// </summary>
        public void Apply()
        {
            if (Texture != null)
                Texture.Apply();
        }
        #endregion
        //--------------------------------------------------------//
    }
    //------------------------------------------------------------//
}
